package com.tuuzed.hydrogen.internal;


import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

class HydrogenConfig {
    /**
     * 数据库版本
     */
    private int databaseVersion;
    /**
     * 数据库名
     */
    private String databaseName;
    /**
     * 模型类完整包名
     */
    private String modelPackage;
    /**
     * 是否显示执行的SQL语句
     */
    private boolean echoSQL;

    private HydrogenConfig() {
    }


    public int getDatabaseVersion() {
        return databaseVersion;
    }

    public String getDatabaseName() {
        return databaseName;
    }

    public String getModelPackage() {
        return modelPackage;
    }

    public boolean isEchoSQL() {
        return echoSQL;
    }

    public static HydrogenConfig get(Context context) {
        HydrogenConfig config = new HydrogenConfig();
        PackageManager packageManager = context.getPackageManager();
        try {
            String packageName = context.getPackageName();
            ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
            config.databaseVersion = applicationInfo.metaData.getInt("DATABASE_VERSION", 1);
            config.databaseName = applicationInfo.metaData.getString("DATABASE_NAME", packageName.replaceAll("\\.", "_") + ".db");
            config.modelPackage = applicationInfo.metaData.getString("MODEL_PACKAGE", packageName);
            config.echoSQL = applicationInfo.metaData.getBoolean("ECHO_SQL", false);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return config;
    }
}
